package com.collect.tanzania.zhiScene.zhiWidget.zhiMenuView;

import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.collect.tanzania.R;

import butterknife.BindView;
import butterknife.ButterKnife;

public class ZHIDetailTableView extends LinearLayout implements View.OnClickListener{

    private final Context mContext;
    private View mView;
    private String mainText;
    private String detailText;

    private int mainTextColor;
    private int detailTextColor;
    private boolean showExt;
    private boolean showSepLine;

    @BindView(R.id.tv_main_title)
    TextView tv_main_title;
    @BindView(R.id.tv_detail_title)
    TextView tv_detail_title;
    @BindView(R.id.v_line)
    View v_line;

    private OnClickListener onViewClickListener;

    public ZHIDetailTableView(Context context){
        this(context, null);
    }

    public ZHIDetailTableView(Context context, AttributeSet attributeSet){
        this(context, attributeSet, 0);
    }

    public ZHIDetailTableView(Context context, AttributeSet attributeSet, int defStyle){
        super(context, attributeSet, defStyle);

        this.mContext = context;
        TypedArray typedArray = context.obtainStyledAttributes(attributeSet, R.styleable.CFMenuTableView);
        mainText = typedArray.getString(R.styleable.CFMenuTableView_mainText);
        detailText = typedArray.getString(R.styleable.CFMenuTableView_detailText);
        mainTextColor = typedArray.getInt(R.styleable.CFMenuTableView_mainTextColor, R.color.theme_black_0);
        detailTextColor = typedArray.getInt(R.styleable.CFMenuTableView_detailTextColor, R.color.theme_black_1);
        showExt = typedArray.getBoolean(R.styleable.CFMenuTableView_showExt, true);
        showSepLine = typedArray.getBoolean(R.styleable.CFMenuTableView_showSepLine, true);
        typedArray.recycle();

        initView();
    }

    @Override
    public void onDetachedFromWindow() {
        super.onDetachedFromWindow();
    }

    @Override
    public void onClick(View view) {
        if(onViewClickListener != null){
            onViewClickListener.onClick(view);
        }
    }

    /**
     * 初始化组件数据
     * @type  method
     * @author liwenjie
     * @creatTime 2019-10-25 19:43
     */
    private void initView() {
        mView = View.inflate(mContext, R.layout.view_detail_table, this);
        ButterKnife.bind(this);

        tv_main_title.setText(mainText);
        tv_main_title.setTextColor(mainTextColor);

        tv_detail_title.setText(detailText);
        tv_detail_title.setTextColor(detailTextColor);

        v_line.setVisibility(showSepLine ? VISIBLE:GONE);

        mView.setOnClickListener(this);
    }

    /**
     * 设置监听
     * @type  method
     * @author liwenjie
     * @creatTime 2019-10-29 12:45
     */
    public void setOnViewClickListener(OnClickListener onViewClickListener){
        this.onViewClickListener = onViewClickListener;
    }

    /**
     * 设置显示内容
     * @type  method
     * @author liwenjie
     * @creatTime 2019-10-25 19:58
     */
    public void setMainText(String text){
        mainText = text;
        tv_main_title.setText(mainText);
    }

    /**
     * 设置显示内容
     * @type  method
     * @author liwenjie
     * @creatTime 2019-10-25 19:58
     */
    public void setDetailText(String text){
        detailText = text;
        tv_detail_title.setText(detailText);
    }

    /**
     * 获取显示内容
     * @type  method
     * @author liwenjie
     * @creatTime 2019-10-25 19:58
     */
    public String getMainText(){
        return tv_main_title.getText().toString().trim();
    }

    /**
     * 获取显示内容
     * @type  method
     * @author liwenjie
     * @creatTime 2019-10-25 19:58
     */
    public String getDetailText(){
        return tv_detail_title.getText().toString().trim();
    }
}
